package com.wangyadong.hobby.schedule.jobtask.dsa;

import java.util.ArrayDeque;
import java.util.Queue;

class RecentCounter {


    Queue<Integer> queue;
    int interval = 3000;

    public RecentCounter() {
        queue = new ArrayDeque<>();
    }

    public int ping(int t) {
        queue.add(t);
        while (queue.peek() < (t - interval)) {
            queue.poll();
        }
        return queue.size();

    }


    public static void main(String[] args) {
        RecentCounter counter = new RecentCounter();
        System.out.println(counter.ping(1));
        System.out.println(counter.ping(100));
        System.out.println(counter.ping(3001));
        System.out.println(counter.ping(3002));
    }
}

/**
 * Your RecentCounter object will be instantiated and called as such:
 * RecentCounter obj = new RecentCounter();
 * int param_1 = obj.ping(t);
 */